<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>db — Database &mdash; Documentation</title>
    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="Documentation" href="index.html" />
    <link rel="up" title="Server Side Internals" href="server_side_internals.html" />
    <link rel="next" title="page_body — Page Body Serverside Module" href="page_body.html" />
    <link rel="prev" title="db_schema — Database Schema Management Module" href="db_schema.html" /> 
  </head>
  <body>
    <div style="background-color: #FFF; text-align: left; padding: 8px 0px"><img src="_static/banner300910.gif"></div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="page_body.html" title="page_body — Page Body Serverside Module"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="db_schema.html" title="db_schema — Database Schema Management Module"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Documentation</a> &raquo;</li>
          <li><a href="server_side_api.html" >3. Server Side API</a> &raquo;</li>
          <li><a href="server_side_internals.html" accesskey="U">Server Side Internals</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">db</span></tt> &#8212; Database</a><ul>
<li><a class="reference external" href="#database-object-conn">database object &#8212; conn</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="db_schema.html"
                                  title="previous chapter"><tt class="docutils literal docutils literal"><span class="pre">db_schema</span></tt> &#8212; Database Schema Management Module</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="page_body.html"
                                  title="next chapter"><tt class="docutils literal"><span class="pre">page_body</span></tt> &#8212; Page Body Serverside Module</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/db.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-db">
<h1><tt class="xref docutils literal"><span class="pre">db</span></tt> &#8212; Database<a class="headerlink" href="#module-db" title="Permalink to this headline">¶</a></h1>
<div class="section" id="database-object-conn">
<h2>database object &#8212; conn<a class="headerlink" href="#database-object-conn" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt>
<tt class="descname">Database(host='', user='', password='', use_default = 0):</tt></dt>
<dd><p>Open a database connection with the given parmeters, if use_default is True, use the
login details from <cite>defs.py</cite>. This is called by the request handler and is accessible using
the <cite>conn</cite> global variable. the <cite>sql</cite> method is also global to run queries</p>
<dl class="attribute">
<dt id="db.host">
<tt class="descclassname">db.</tt><tt class="descname">host</tt><a class="headerlink" href="#db.host" title="Permalink to this definition">¶</a></dt>
<dd>Database host or &#8216;localhost&#8217;</dd></dl>

<dl class="attribute">
<dt id="db.user">
<tt class="descclassname">db.</tt><tt class="descname">user</tt><a class="headerlink" href="#db.user" title="Permalink to this definition">¶</a></dt>
<dd>Database user</dd></dl>

<dl class="attribute">
<dt id="db.password">
<tt class="descclassname">db.</tt><tt class="descname">password</tt><a class="headerlink" href="#db.password" title="Permalink to this definition">¶</a></dt>
<dd>Database password - cleared after connection is made</dd></dl>

<dl class="attribute">
<dt id="db.is_testing">
<tt class="descclassname">db.</tt><tt class="descname">is_testing</tt><a class="headerlink" href="#db.is_testing" title="Permalink to this definition">¶</a></dt>
<dd>1 if session is in <cite>Testing Mode</cite> else 0</dd></dl>

<dl class="attribute">
<dt id="db.in_transaction">
<tt class="descclassname">db.</tt><tt class="descname">in_transaction</tt><a class="headerlink" href="#db.in_transaction" title="Permalink to this definition">¶</a></dt>
<dd>1 if connection is in a Transaction else 0</dd></dl>

<dl class="attribute">
<dt id="db.testing_tables">
<tt class="descclassname">db.</tt><tt class="descname">testing_tables</tt><a class="headerlink" href="#db.testing_tables" title="Permalink to this definition">¶</a></dt>
<dd>list of tables, tables with <cite>tab</cite> + doctype</dd></dl>

<dl class="method">
<dt id="db.connect">
<tt class="descclassname">db.</tt><tt class="descname">connect</tt><big>(</big><big>)</big><a class="headerlink" href="#db.connect" title="Permalink to this definition">¶</a></dt>
<dd>Connect to a database</dd></dl>

<dl class="method">
<dt id="db.use">
<tt class="descclassname">db.</tt><tt class="descname">use</tt><big>(</big><em>db_name</em><big>)</big><a class="headerlink" href="#db.use" title="Permalink to this definition">¶</a></dt>
<dd><cite>USE</cite> db_name</dd></dl>

<dl class="method">
<dt id="db.set_db">
<tt class="descclassname">db.</tt><tt class="descname">set_db</tt><big>(</big><em>account</em><big>)</big><a class="headerlink" href="#db.set_db" title="Permalink to this definition">¶</a></dt>
<dd>Switch to database of given <cite>account</cite></dd></dl>

<dl class="method">
<dt id="db.check_transaction_status">
<tt class="descclassname">db.</tt><tt class="descname">check_transaction_status</tt><big>(</big><em>query</em><big>)</big><a class="headerlink" href="#db.check_transaction_status" title="Permalink to this definition">¶</a></dt>
<dd>Update <em>in_transaction</em> and check if &#8220;START TRANSACTION&#8221; is not called twice</dd></dl>

<dl class="method">
<dt id="db.fetch_as_dict">
<tt class="descclassname">db.</tt><tt class="descname">fetch_as_dict</tt><big>(</big><big>)</big><a class="headerlink" href="#db.fetch_as_dict" title="Permalink to this definition">¶</a></dt>
<dd>Internal - get results as dictionary</dd></dl>

<dl class="method">
<dt id="db.sql">
<tt class="descclassname">db.</tt><tt class="descname">sql</tt><big>(</big><em>query</em>, <em>values=()</em>, <em>as_dict = 0</em>, <em>as_list = 0</em>, <em>allow_testing = 1</em><big>)</big><a class="headerlink" href="#db.sql" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Execute a <cite>query</cite>, with given <cite>values</cite></li>
<li>returns as a dictionary if as_dict = 1</li>
<li>returns as a list of lists (with cleaned up dates and decimals) if as_list = 1</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="db.convert_to_lists">
<tt class="descclassname">db.</tt><tt class="descname">convert_to_lists</tt><big>(</big><em>res</em><big>)</big><a class="headerlink" href="#db.convert_to_lists" title="Permalink to this definition">¶</a></dt>
<dd>Convert the given result set to a list of lists (with cleaned up dates and decimals)</dd></dl>

<dl class="method">
<dt id="db.replace_tab_by_test">
<tt class="descclassname">db.</tt><tt class="descname">replace_tab_by_test</tt><big>(</big><em>query</em><big>)</big><a class="headerlink" href="#db.replace_tab_by_test" title="Permalink to this definition">¶</a></dt>
<dd>Relace all <tt class="docutils literal"><span class="pre">tab</span></tt> + doctype to <tt class="docutils literal"><span class="pre">test</span></tt> + doctype</dd></dl>

<dl class="method">
<dt id="db.get_testing_tables">
<tt class="descclassname">db.</tt><tt class="descname">get_testing_tables</tt><big>(</big><big>)</big><a class="headerlink" href="#db.get_testing_tables" title="Permalink to this definition">¶</a></dt>
<dd>Get list of all tables for which <cite>tab</cite> is to be replaced by <cite>test</cite> before a query is executed</dd></dl>

<dl class="method">
<dt id="db.get_value">
<tt class="descclassname">db.</tt><tt class="descname">get_value</tt><big>(</big><em>doctype</em>, <em>docname</em>, <em>fieldname</em><big>)</big><a class="headerlink" href="#db.get_value" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a single value from a record.</p>
<p>For Single records, let docname be = None</p>
</dd></dl>

<dl class="method">
<dt id="db.get_description">
<tt class="descclassname">db.</tt><tt class="descname">get_description</tt><big>(</big><big>)</big><a class="headerlink" href="#db.get_description" title="Permalink to this definition">¶</a></dt>
<dd>Get metadata of the last query</dd></dl>

<dl class="method">
<dt id="db.field_exists">
<tt class="descclassname">db.</tt><tt class="descname">field_exists</tt><big>(</big><em>dt</em>, <em>fn</em><big>)</big><a class="headerlink" href="#db.field_exists" title="Permalink to this definition">¶</a></dt>
<dd>Returns True if <cite>fn</cite> exists in <cite>DocType</cite> <cite>dt</cite></dd></dl>

<dl class="method">
<dt id="db.exists">
<tt class="descclassname">db.</tt><tt class="descname">exists</tt><big>(</big><em>dt</em>, <em>dn</em><big>)</big><a class="headerlink" href="#db.exists" title="Permalink to this definition">¶</a></dt>
<dd>Returns true if the record exists</dd></dl>

<dl class="method">
<dt id="db.close">
<tt class="descclassname">db.</tt><tt class="descname">close</tt><big>(</big><big>)</big><a class="headerlink" href="#db.close" title="Permalink to this definition">¶</a></dt>
<dd>Close my connection</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="page_body.html" title="page_body — Page Body Serverside Module"
             >next</a> |</li>
        <li class="right" >
          <a href="db_schema.html" title="db_schema — Database Schema Management Module"
             >previous</a> |</li>
        <li><a href="index.html">Documentation</a> &raquo;</li>
          <li><a href="server_side_api.html" >3. Server Side API</a> &raquo;</li>
          <li><a href="server_side_internals.html" >Server Side Internals</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2010, Rushabh Mehta.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>